/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package utils.ftp;

import entidades.ConfigFTP;
import exceptions.ConfigFTPIncorrecta;
import java.io.FileOutputStream;
import org.apache.commons.net.io.CopyStreamAdapter;

/**
 *
 * @author Felipe
 */
public class Download extends FTPManager
{
    private String origen, destino;

    public Download(CopyStreamAdapter listener, String destino, String origen) throws ConfigFTPIncorrecta
    {
        super(listener);
        
        this.origen = origen;
        this.destino = destino;
    }

    @Override
    public void run()
    {
        try
        {
            if (!cliente.isConnected())
                conectar();
            
            FileOutputStream fos = new FileOutputStream(destino);
            
            cliente.retrieveFile("/" + config.getDirectorio() + "/" + origen, fos);
            fos.close();
            
            cliente.logout();
            cliente.disconnect();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    
}
